#绘制ReLU与LeakeyReLU函数图像
import numpy as np
import matplotlib.pyplot as plt

def ReLU(x):
    return np.maximum(0, x)

def LeakyReLU(x):
    return np.maximum(0.01*x, x)

x = np.linspace(-5, 5, 100)
y1 = ReLU(x)
y2 = LeakyReLU(x)

plt.plot(x, y2, label='LeakyReLU', color='r')
#绘制坐标系
plt.axhline(0, color='black',linewidth=0.5)
plt.axvline(0, color='black',linewidth=0.5)
#绘制网格

plt.grid()
#plt.title('ReLU and LeakyReLU')
plt.xlabel('x')
plt.ylabel('LeakyReLU(x)')
#去除上边框和右边框
plt.gca().spines['top'].set_visible(False)
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['bottom'].set_visible(False)
plt.gca().spines['left'].set_visible(False)
#plt.plot(x, y2, label='LeakyReLU', color='b')
plt.legend()
plt.show()
